﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeatlesBlog.SimConnect;
using FA.Library.Sim.Aircraft;
using FA.Library.Util;
using System.ComponentModel;

namespace FA.Plugins.FSXPlugin.Sim.Aircraft
{
    [DataStruct()]
    public class FSXAircraftControls : BaseCloneable, AircraftControls
    {
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// True if landing gear handle is applied.
        /// </summary>
        [DataItem("GEAR HANDLE POSITION", "bool")]
        public bool LandingGearApplied
        {
            get { return _landingGearApplied; }
            set
            {
                if (_landingGearApplied != value)
                {
                    _landingGearApplied = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("LandingGearApplied"));
                }
            }
        }
        private bool _landingGearApplied;

        /// <summary>
        /// Percent control deflection fore/aft (for animation).
        /// 
        /// (-16K to 0) -16K = Yoke fully pushed in
        /// </summary>
        [DataItem("YOKE Y POSITION", "position")]
        public float YokeYPosition
        {
            get { return _yokeYPos; }
            set
            {
                if (_yokeYPos != value)
                {
                    _yokeYPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("YokeYPosition"));
                }
            }
        }
        private float _yokeYPos;

        /// <summary>
        /// Percent control deflection left/right (for animation).
        /// </summary>
        [DataItem("YOKE X POSITION", "position")]
        public float YokeXPosition
        {
            get { return yokeXPos; }
            set
            {
                if (yokeXPos != value)
                {
                    yokeXPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("YokeXPosition"));
                }
            }
        }
        private float yokeXPos;

        /// <summary>
        /// Percent rudder pedal deflection (for animation).
        /// 
        /// (-16K to 0) -16K = left pedal pushed full in
        /// </summary>
        [DataItem("RUDDER PEDAL POSITION", "position")]
        public float RudderPedalPosition
        {
            get { return _rudderPedalPos; }
            set
            {
                if (_rudderPedalPos != value)
                {
                    _rudderPedalPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("RudderPedalPosition"));
                }
            }
        }
        private float _rudderPedalPos;

        /// <summary>
        /// Percent rudder input deflection.
        /// 
        /// (-16K to 0) -16K = full left 
        /// </summary>
        [DataItem("RUDDER POSITION", "position")]
        public float RudderPosition
        {
            get { return _rudderPos; }
            set
            {
                if (_rudderPos != value)
                {
                    _rudderPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("RudderPosition"));
                }
            }
        }
        private float _rudderPos;

        /// <summary>
        /// Percent elevator input deflection.
        /// 
        /// (-16K to 0) -16K = full down.
        /// </summary>
        [DataItem("ELEVATOR POSITION", "position")]
        public float ElevatorPosition
        {
            get { return _elevatorPos; }
            set
            {
                if (_elevatorPos != value)
                {
                    _elevatorPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("ElevatorPosition"));
                }
            }
        }
        private float _elevatorPos;

        /// <summary>
        /// Percent aileron input left/right.
        /// 
        /// (-16K to 0) -16K = full left 
        /// </summary>
        [DataItem("AILERON POSITION", "position")]
        public float AileronPosition
        {
            get { return _aileronPos; }
            set
            {
                if (_aileronPos != value)
                {
                    _aileronPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("AileronPosition"));
                }
            }
        }
        private float _aileronPos;

        /// <summary>
        /// Elevator trim deflection.
        /// </summary>
        [DataItem("ELEVATOR TRIM POSITION", "radians")]
        public float ElevatorTrim
        {
            get { return _elevatorTrimPos; }
            set
            {
                if (_elevatorTrimPos != value)
                {
                    _elevatorTrimPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("ElevatorTrimPosition"));
                }
            }
        }
        private float _elevatorTrimPos;

        /// <summary>
        /// Percent left brake.
        /// 
        /// (0 to 32K) 0 = off, 32K full.
        /// </summary>
        [DataItem("BRAKE LEFT POSITION", "position")]
        public float BrakeLeftPosition
        {
            get { return _brakeLeftPos; }
            set
            {
                if (_brakeLeftPos != value)
                {
                    _brakeLeftPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("BrakeLeftPosition"));
                }
            }
        }
        private float _brakeLeftPos;

        /// <summary>
        /// Percent right brake.
        /// 
        /// (0 to 32K) 0 = off, 32K full.
        /// </summary>
        [DataItem("BRAKE RIGHT POSITION", "position")]
        public float BrakeRightPosition
        {
            get { return _brakeRightPos; }
            set
            {
                if (_brakeRightPos != value)
                {
                    _brakeRightPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("BrakeRightPosition"));
                }
            }
        }
        private float _brakeRightPos;

        /// <summary>
        /// Parking brake on.
        /// 
        /// (0 to 32K) 0 = off, 32K full
        /// </summary>
        [DataItem("BRAKE PARKING POSITION", "position")]
        public float BrakeParkingPosition
        {
            get { return _brakeParkingPos; }
            set
            {
                if (_brakeParkingPos != value)
                {
                    _brakeParkingPos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("BrakeParkingPosition"));
                }
            }
        }
        private float _brakeParkingPos;

        /// <summary>
        /// Parking brake indicator.
        /// </summary>
        [DataItem("BRAKE PARKING INDICATOR", "bool")]
        public bool BrakeParkingIndicator
        {
            get { return _brakeParkingIndicator; }
            private set
            {
                if (_brakeParkingIndicator != value)
                {
                    _brakeParkingIndicator = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("BrakeParkingIndicator"));
                }
            }
        }
        private bool _brakeParkingIndicator;

        /// <summary>
        /// Spoiler handle position.
        /// 
        /// Position (16K = down, 0 = up) 
        /// </summary>
        [DataItem("SPOILERS HANDLE POSITION", "position")]
        public float SpoilerHandlePosition
        {
            get { return _spoilerHandlePos; }
            set
            {
                if (_spoilerHandlePos != value)
                {
                    _spoilerHandlePos = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("SpoilerHandlePosition"));
                }
            }
        }
        private float _spoilerHandlePos;

        /// <summary>
        /// Index of current flap position.
        /// </summary>
        [DataItem("FLAPS HANDLE INDEX", 32)]
        public int FlapIndex
        {
            get { return _flapHandleIndex; }
            set
            {
                if (_flapHandleIndex != value)
                {
                    _flapHandleIndex = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("FlapHandleIndex"));
                }
            }
        }
        private int _flapHandleIndex;

        /// <summary>
        /// Percent left trailing edge flap extended.
        /// </summary>
        [DataItem("TRAILING EDGE FLAPS LEFT PERCENT", "percent")]
        public float LeftTrailingEdgeFlap
        {
            get { return _leftTrailingEdgeFlap; }
            set
            {
                if (_leftTrailingEdgeFlap != value)
                {
                    _leftTrailingEdgeFlap = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("LeftTrailingEdgeFlap"));
                }
            }
        }
        private float _leftTrailingEdgeFlap;

        /// <summary>
        /// Percent right trailing edge flap extended.
        /// </summary>
        [DataItem("TRAILING EDGE FLAPS RIGHT PERCENT", "percent")]
        public float RightTrailingEdgeFlap
        {
            get { return _rightTrailingEdgeFlap; }
            set
            {
                if (_rightTrailingEdgeFlap != value)
                {
                    _rightTrailingEdgeFlap = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("RightTrailingEdgeFlap"));
                }
            }
        }
        private float _rightTrailingEdgeFlap;

        /// <summary>
        /// Percent left leading edge flap extended.
        /// </summary>
        [DataItem("LEADING EDGE FLAPS LEFT PERCENT", "percent")]
        public float LeftLeadingEdgeFlap
        {
            get { return _leftLeadingEdgeFlap; }
            set
            {
                if (_leftLeadingEdgeFlap != value)
                {
                    _leftLeadingEdgeFlap = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("LeftLeadingEdgeFlap"));
                }
            }
        }
        private float _leftLeadingEdgeFlap;

        /// <summary>
        /// Percent right leading edge flap extended.
        /// </summary>
        [DataItem("LEADING EDGE FLAPS RIGHT PERCENT", "percent")]
        public float RightLeadingEdgeFlap
        {
            get { return _rightLeadingEdgeFlap; }
            set
            {
                if (_rightLeadingEdgeFlap != value)
                {
                    _rightLeadingEdgeFlap = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("RightLeadingEdgeFlap"));
                }
            }
        }
        private float _rightLeadingEdgeFlap;

        /// <summary>
        /// Percent deflection of aileron trim.
        /// </summary>
        [DataItem("AILERON TRIM PCT", "percent")]
        public float AileronTrim
        {
            get { return _aileronTrim; }
            set
            {
                if (_aileronTrim != value)
                {
                    _aileronTrim = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("AileronTrim"));
                }
            }
        }
        private float _aileronTrim;

        /// <summary>
        /// Percent deflection of rudder trim.
        /// </summary>
        [DataItem("RUDDER TRIM PCT", "percent")]
        public float RudderTrim
        {
            get { return _rudderTrim; }
            set
            {
                if (_rudderTrim != value)
                {
                    _rudderTrim = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("RudderTrim"));
                }
            }
        }
        private float _rudderTrim;
    }
}